package com.aaa.marketresearch.webclient.gwt.domain;

import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;

/**
 * @author Nail
 */
public class Family {

    private Integer id;
    private String name;
    private String email;
    private String password;
    private String role;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Family() {
        this.id = null;
        this.name = "";
        this.email = "";
        this.password = "";
        this.role = "USER";
    }

    public Family(JSONObject jObj) {
        this.id = (int)jObj.get("id").isNumber().doubleValue();
        this.name = jObj.get("name").isString().stringValue();
        this.email = jObj.get("email").isString().stringValue();
        this.password = jObj.get("password").isString().stringValue();
        this.role = jObj.get("role").isString().stringValue();
    }

    public JSONObject getJSON() {
        JSONObject jObj = new JSONObject();
        if (this.id != null) {
            jObj.put("id", new JSONNumber(this.id));
        }

        jObj.put("name", new JSONString(this.name));
        jObj.put("email", new JSONString(this.email));
        jObj.put("password", new JSONString(this.password));
        jObj.put("role", new JSONString(this.role));
        return jObj;
    }
}